<template>
	<view class="zone">
		<u-navbar :is-back="false" :height="60" :background="background" :border-bottom="false">
			<view class="slot-wrap">
				<view class="nav-bar2">
					<u-icon class="back" size="20px" color="#fff" @click="$p.back()" name="arrow-left"></u-icon>
					<view class="n_left">
						 <image src="http://img.cpgm.cc/panda/static/invite/tasktitle.png" mode="widthFix" /> 
					</view>
				</view>
			</view>
		</u-navbar>

		<!-- 天庭的任务 -->
		<view class="main">
			<p class="title">天庭里最近发生了不少事，人手不够，玩家参与并完成天庭任务，可以获得大量水晶奖励</p>

			<!-- tab部分 -->
			<view class="tab">
				<view v-for="(item,index) in tablist" :key="index" :class="[stat == item.id?'active':'']"
					@click="tabchange(item.id)">{{item.name}}</view>
			</view>

			<view class="list" v-show="stat == 1">
				<view class="itme" v-for="(item,index) in list" :key="index">
					<view class="left">
						<image :src="`http://img.cpgm.cc/panda/static/invitebox/${item.id}.png`" mode="widthFix" />
						<view class="word">
							<p>{{item.name}}的任务</p>
							<p>任务消耗 <text>{{item.consume}}</text> 水晶</p>
							<p>任务产出 <text>{{item.output}}</text> 水晶</p>
						</view>
					</view>
					<view class="right">
						<view class="button btn1" @click="taskdetail(item)">任务详情</view>
						<view class="button btn2" :class="[item.is_task?'already':'']" @click="receive(item)">{{item.is_task?'已接取':'接取任务'}}</view>
					</view>
				</view>
			</view>

			<view class="list" v-show="stat == 2">
				<view class="itme" v-for="(item , index) in list2" :key="index"> 
					<view class="left">
						<image :src="`http://img.cpgm.cc/panda/static/invitebox/${item.id}.png`" mode="widthFix" />
						<view class="word">
							<p>{{item.name}}的任务</p>
							<p>任务消耗 <text>{{item.consume}}</text> 水晶</p>
							<p>任务产出 <text>{{item.output}}</text> 水晶</p>
							<p>任务有效期 <text>{{item.days}}</text>天</p>
						</view>
					</view>
					<view class="right">
						<u-button :plain="true" :hair-line="false" hover-class="none" :throttle-time="1000" :class="[!!item.is_rece?'btn1':'']" @click="getJobReward(item)" class="button btn3">{{!!item.is_rece?'今日已领取':'领取奖励'}}</u-button>
					</view>
				</view>
				<view class="empty" v-if="list2 == ''">
					<image src="http://img.cpgm.cc/panda/static/duoBao/baiwu.png" mode="widthFix" />
					<text>数据为空</text>
				</view>
			</view>
		</view>

		<!-- 接取任务 -->
		<u-mask :show="taskshow">
			<view class="warp">
				<view class="mask_box">
					<view class="m_tit">接取任务</view>
					<p>是否消耗 <text>{{receivedata.gold}}</text> 水晶接取{{receivedata.name}}的任务？</p>
					<view class="m_btnbox">
						<view class="button cancel" @click="taskshow = false">取消</view>
						<u-button :plain="true" :hair-line="false" hover-class="none" :throttle-time="1000" class="button confirm" @click="confirm_task()">确定</u-button>
					</view>
				</view>
			</view>
		</u-mask>
		

		<!-- 取消任务 -->
		<u-mask :show="taskshow2">
			<view class="warp">
				<view class="mask_box">
					<view class="m_tit">取消任务</view>
					<p>是否取消太白金星的任务？</p>
					<view class="m_btnbox">
						<view class="button cancel" @click="taskshow2 = false">取消</view>
						<view class="button confirm">确定</view>
					</view>
				</view>
			</view>
		</u-mask>

		<u-mask :show="show2">
			<view class="warp">
				<!-- <image src="" mode="" /> -->
				<view class="maskbox mbg2">
					<img class="masktit" src="http://img.cpgm.cc/panda/static/feed/masktit.png" alt="">
					<view class="m_title m_title2">
						<text>恭喜您</text>
					</view>
					<view class="whitebg">
						<p>成功领取<text>{{reward}}</text>水晶</p>
						<image src="http://img.cpgm.cc/panda/static/index/3.png" mode="widthFix" />
						<view class="maskbtn">
							<view class="button btn3" @click="show2 = false">开心收下</view>
						</view>
					</view>
				</view>
			</view>
		</u-mask>

		<!-- 任务详情 -->
		<u-mask :show="detailshow">
			<view class="warp">
				<image class="posaimg" src="http://img.cpgm.cc/panda/static/public/masktop.png" mode="widthFix" />
				<view class="detailbox">
					<view class="m_top">
						<h3>任务详情</h3>
						<image @click="detailshow = false" src="http://img.cpgm.cc/panda/static/feed/cha.png" mode="widthFix" />
					</view>
					<view class="grebox">
						<view class="exbox">
							<text>任务等级</text>
							<view class="line"></view>
							<view class="rigbox">{{detail.lv}}</view>
						</view>
						<view class="exbox">
							<text>任务消耗</text>
							<view class="line"></view>
							<view class="rigbox red">{{detail.consume}}水晶</view>
						</view>
						<view class="exbox">
							<text>任务产出</text>
							<view class="line"></view>
							<view class="rigbox red">{{detail.output}}水晶</view>
						</view>
						<!-- <view class="exbox">
							<text>任务产出率</text>
							<view class="line"></view>
							<view class="rigbox">{{getgail(detail)}}%</view>
						</view> -->
						<view class="exbox">
							<text>任务有效期</text>
							<view class="line"></view>
							<view class="rigbox">30天</view>
						</view>
					</view>
				</view>
			</view>
		</u-mask>

		
	</view>
</template>


<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#000',
				},
				tablist: [{
						id: 1,
						name: '接取任务'
					},
					{
						id: 2,
						name: '任务奖励'
					},
				],
				stat: 1,
				userinfo: uni.getStorageSync('userinfo'),
				list:[
					{
						id:12,
						consume:100, // 消耗
						output:132, // 产出
						name:'太白金星',
						lv:1,
					},
					{
						id:13,
						consume:1000, // 消耗
						output:1320, // 产出
						name:'镇元子',
						lv:2,
					},
					{
						id:14,
						consume:5000, // 消耗
						output:6540, // 产出
						name:'太上老君',
						lv:3,
					},
					{
						id:15,
						consume:20000, // 消耗
						output:26400, // 产出
						name:'王母',
						lv:4,
					},
					{
						id:16,
						consume:80000, // 消耗
						output:104400, // 产出
						name:'玉帝',
						lv:5,
					},
					{
						id:17,
						consume:200000, // 消耗
						output:261000, // 产出
						name:'观音',
						lv:6,
					},
				],
				taskshow:false,
				show2:false,
				taskshow2:false,
				detailshow:false,
				detail:'',
				tasklist:'',
				receivedata:'',
				list2:[],
				reward:'',
			};
		},

		onLoad(){
			this.getUserInfo();
			this.jobList();
		},
		methods: {
			// 获取个人信息
			getUserInfo(){
				this.$getUserInfo.getUserInfo((res)=>{
					this.userinfo = res.data
				})
			},

			getgail(item){
				let a = (item.output - item.gold) / item.gold
				return a * 100
			},
			// 我的背包切换
			tabchange(id) {
				this.stat = id
			},

			taskdetail(item){
				this.detail = item
				this.detailshow = true
			},	

			// 领取显示弹窗 
			receive(item){
				if(!!item.is_task) {
					this.$u.toast('已接取')
				}else {
					this.receivedata = item;
					this.taskshow = true
				}
			},

			// 天庭任务列表
			async jobList(){
				this.list2 = []
				let res = await this.$http.index.jobList();
				for (let i = 0; i < res.data.length; i++) {
					this.list[i] = {...this.list[i] , ...res.data[i]}
					if(!!this.list[i].is_task) {
						this.list2.push(this.list[i])
					}
				}
				
				this.$forceUpdate()
			},

			// 接取任务
			async confirm_task(){
				let res = await this.$http.index.buyJob({
					type:this.receivedata.type
				})
				this.$u.toast(res.msg)
				if(res.code == 1) {
					this.jobList();
					this.taskshow = false
				}
			},

			// 领取奖励
			async getJobReward(item){
				if(!!item.is_rece) {
					this.$u.toast('今日已领取')
				}else {
					let res = await this.$http.index.getJobReward({
						type:item.type
					})
					if(res.code == 1) {
						this.reward = res.reward
						this.show2 = true
						this.jobList();
					}else {
						this.$u.toast(res.msg)
					}
				}
				
			},
			
		},
	}

</script>

<style lang="less">
.zone {
	background: #000;
	min-height: 100vh;
}

.nav-bar2 {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	min-height: 60px;
	padding: 0px 10px;
}

.n_left {
	width: 100%;
	display: flex;
	align-items: flex-end;
	text {
		color: rgba(255, 255, 255, 0.8);
		font-size: 12px;
		margin-left: 5px;
		margin-bottom: 10px;
	}
	image {
			width: 35%;
			margin-left: 5px;
		}
}

.shouxu {
	color: #fff;
	font-size: 14px;
}


.main {
	padding: 10px;
}

.title {
	color: #fff;
	font-size: 12px;
}


// tab导航
	.tab {
		width: 100%;
		display: flex;
		align-items: center;
		background: #fff;
		box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.1);
		border-radius: 5px;
		padding: 5px;
		overflow: hidden;
		margin: 10px auto;
		border-radius: 7px;
		// backdrop-filter: blur(50px);

		view {
			width: 50%;
			height: 42px;
			text-align: center;
			line-height: 42px;
			color: rgba(52, 52, 52, 0.61);
			font-size: 13px;
			font-weight: 600;
			border-radius: 7px;
		}
	}
	.active {
		color: #FFFFFF !important;
		background: #000000 linear-gradient(270deg, #FF456B 0%, #FE5C4F 100%)  !important;
	}

	.list {
		margin-top: 10px;
	}

	.itme {
		background: linear-gradient(180deg, #FFFFFF 0%, #ECECEC 100%);
		border-radius: 7px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10px;
		margin-bottom: 10px;

		.left {
			display: flex;
			align-items: center;

			image {
				width: 90px;
			}
			.word {
				p:nth-child(1) {
					color: #000000;
					font-size: 14px;
					font-weight: 600;
				}
				p:nth-child(2) {
					color: #343434;
					font-size: 12px;
					margin: 5px 0;
					text {
						color: #FF4767;
						font-weight: 600;
					}
				}
				p:nth-child(3) {
					color: #343434;
					font-size: 12px;
					text {
						color: #FF4767;
						font-weight: 600;
					}
				}
				p:nth-child(4) {
					color: #343434;
					font-size: 12px;
					margin-top: 5px;
					text {
						color: #FF4767;
						font-weight: 600;
					}
				}
			}
		}

		.right {
			display: flex;
			flex-direction: column;
			align-items: center;

			.button {
				width: 82px;
				height: 33px;
				border-radius: 5px;
				font-size: 12px;
				
			}

			.btn1 {
				background: linear-gradient(270deg, rgba(255,69,107,0.1) 0%, rgba(254,92,79,0.1) 100%) !important;
				border: 1px solid #FF4768 !important;
				color: #FF4767 !important;
			}

			.btn2 {
				background: #000000;
				border: 1px solid #000000;
				color: #fff;
				margin-top: 8px;
			}

			.btn3 {
				background: linear-gradient(270deg, #FF456B 0%, #FE5C4F 100%);
				color: #fff;
				margin-top: 8px;
			}
		}
	}



	// 领取弹窗

	.mask_box {
		background: #FFFFFF;
		border-radius: 5px;
		padding: 15px;

		p {
			color: #696969;
			font-size: 16px;
			margin: 20px 0;
			text-align: center;

			text {
				color: #000;
				font-weight: 600;
			}
		}
	}

	.m_tit {
		font-size: 24px;
		font-weight: 600;
		text-align: center;
	}

	.m_btnbox { 
		display: flex;
		align-items: center;
		justify-content: space-evenly;

		.button {
			width: 40%;
			height: 50px;
			border-radius: 5px;
			font-weight: 600;
		}

		.cancel {
			background: #EAEAEA;
			color: #000;
		}

		.confirm {
			background: linear-gradient(270deg, #FF456B 0%, #FE5C4F 100%);
			color: #fff;
		}
	}





// 领取成功

	.maskbox {
		background: #fff;
		border-radius: 18px;
		padding: 15px 10px;
		p {
			text-align: center;
			margin-top: 10px;
			text {
				color: #239D4C;
				font-weight: 600;
			}
		}

		.m_meat {
			display: flex;
			align-items: center;
			justify-content: center;
		}
		image {
			width: 80px;
		}
	}
.mbg2 {
		padding-top: 30px;
		background: linear-gradient(180deg, #C7DDDA 0%, #FFFFFF 100%);
		box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.1);
		border-radius: 18px;
	}

	.masktit {
		position: relative;
		left: 5%;
		width: 90%;
		margin: 0 auto;
		margin-top: -50%;
	}

	.whitebg {
		padding: 20px;
		border-radius: 9px;
		margin-top: 10px;
		display: flex;
		flex-direction: column;
		align-items: center;

		image {
			width: 80px;
		}
		p {
			color: #696969;
			font-size: 14px;

			text {
				color: #000000;
			}
		}
	}
	

	.m_title2 {
		text {
			font-size: 25px !important;
			color: #000000 !important;
		}
	}


	.m_title {
		display: flex;
		align-items: center;
		justify-content: center;
	}

.maskbtn {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 20px;
}

.btn3 {
	width: 90%;
	height: 50px;
	margin: 0 10px;
	background: linear-gradient(270deg, #FF456B 0%, #FE5C4F 100%);
	border-radius: 5px;
	color: #fff;
	font-weight: 600;
}



// 任务详情

.detailbox {
	background: #fff;
	padding: 10px;
	border-radius: 0 5px 5px 5px;
}

.posaimg {
	position: absolute;
	top: 0;
	transform: translateY(-90%);
	width: 50%;
}

.m_top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 20px;

	image {
		width: 35px;
	}
}

.grebox {
	background: #F7F7F7;
	padding: 10px;
	margin-top: 10px;
}

.exbox {
	display: flex;
	align-items: center;
	margin: 5px 0;

	.line {
		flex: 1;
		border-top: 1px dotted #979797;
		margin: 0 8px;
	}

	text {
		color: #000;
		font-weight: 600;
	}
}

.rigbox {
	min-width: 50px;
	padding: 4px;
	background: #fff;
	text-align: right;
	border-radius: 5px;
	font-weight: 600;
}



.already {
	border-radius: 5px;
	border: 1px solid #000000 !important;
	background: #fff !important;
	color: #000 !important;
}

.red {
	color: #FF4767 !important;
}

</style>
